$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'brdy7/b108basiclivingallowancesrate/list',
        datatype: "json",
        colModel: [			
			{ label: 'basiclivingId', name: 'basiclivingId', index: 'basicliving_id', width: 50, key: true },
			{ label: '年份', name: 'year', index: 'year', width: 80 }, 			
			{ label: '最低生活保障标准', name: 'basicLivingAllowancesStand', index: 'basic_living_allowances_stand', width: 80 }, 			
			{ label: '人均消费支出', name: 'perCapitaConsumptionExpenditure', index: 'per_capita_consumption_expenditure', width: 80 }, 			
			{ label: '低保保障收入比例', name: 'basicRate', index: 'basic_rate', width: 80 }, 			
			{ label: '文件路径', name: 'filepath', index: 'filepath', width: 80 }, 			
			{ label: '录入人', name: 'creatby', index: 'creatby', width: 80  ,hidden:true},
			{ label: '录入时间', name: 'creatat', index: 'creatat', width: 80  ,hidden:true},
			{ label: '上级部门', name: 'parentCode', index: 'parent_code', width: 80  ,hidden:true},
			{ label: '类型编码', name: 'typeCode', index: 'type_code', width: 80  ,hidden:true},
			{ label: '更新时间', name: 'updateTime', index: 'update_time', width: 80  ,hidden:true}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
        q:{
            name: null
        },
		showList: true,
        flag:true,
		title: null,
		b108BasicLivingAllowancesRate: {}
	},
    //mounted:function(){
//   this.initonezb();
//},
	methods: {

		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
            vm.flag=false;
			vm.b108BasicLivingAllowancesRate = {};
		},
		update: function (event) {
			var basiclivingId = getSelectedRow();
			if(basiclivingId == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            vm.flag=true;
            
            vm.getInfo(basiclivingId)
		},
		saveOrUpdate: function (event) {
            if(!$('form').data("bootstrapValidator").isValid()){
                alert("表单验证没通过");
                return;
            };
		    $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function() {
                var url = vm.b108BasicLivingAllowancesRate.basiclivingId == null ? "brdy7/b108basiclivingallowancesrate/save" : "brdy7/b108basiclivingallowancesrate/update";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.b108BasicLivingAllowancesRate),
                    success: function(r){
                        if(r.code === 0){
                             layer.msg("操作成功", {icon: 1});
                             vm.reload();
                             $('#btnSaveOrUpdate').button('reset');
                             $('#btnSaveOrUpdate').dequeue();
                        }else{
                            layer.alert(r.msg);
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }
                    }
                });
			});
		},
		del: function (event) {
			var basiclivingIds = getSelectedRows();
			if(basiclivingIds == null){
				return ;
			}
			var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定','取消'] //按钮
            }, function(){
               if(!lock) {
                    lock = true;
		            $.ajax({
                        type: "POST",
                        url: baseURL + "brdy7/b108basiclivingallowancesrate/delete",
                        contentType: "application/json",
                        data: JSON.stringify(basiclivingIds),
                        success: function(r){
                            if(r.code == 0){
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            }else{
                                layer.alert(r.msg);
                            }
                        }
				    });
			    }
             }, function(){
             });
		},
		getInfo: function(basiclivingId){
			$.get(baseURL + "brdy7/b108basiclivingallowancesrate/info/"+basiclivingId, function(r){
                vm.b108BasicLivingAllowancesRate = r.b108BasicLivingAllowancesRate;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{'name': vm.q.name},
                page:page
            }).trigger("reloadGrid");
		}
	}
});


$(function () {
    $('form').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            //将相关验证js内容粘贴此处并修改数值型字段的上下界
            year: {
                message: '填写失败',
                validators: {
                    notEmpty: {
                        message: '此项信息不能为空'
                    },
                    numeric: {
                        message: '该项数据为数值'
                    },
                    // lessThan: {
                    //     value: 1000,
                    //     message: "最大值为1000"
                    //
                    // },
                    // greaterThan: {
                    //     value: 1,
                    //     message: "最小值为10"
                    // }
                }
            },
            basicLivingAllowancesStand: {
                message: '填写失败',
                validators: {
                    notEmpty: {
                        message: '此项信息不能为空'
                    },
                    numeric: {
                        message: '该项数据为数值'
                    },
                    // lessThan: {
                    //     value: 1000,
                    //     message: "最大值为1000"
                    //
                    // },
                    // greaterThan: {
                    //     value: 1,
                    //     message: "最小值为10"
                    // }
                }
            },
            perCapitaConsumptionExpenditure: {
                message: '填写失败',
                validators: {
                    notEmpty: {
                        message: '此项信息不能为空'
                    },
                    numeric: {
                        message: '该项数据为数值'
                    },
                    // lessThan: {
                    //     value: 1000,
                    //     message: "最大值为1000"
                    //
                    // },
                    // greaterThan: {
                    //     value: 1,
                    //     message: "最小值为10"
                    // }
                }
            },
            basic_rate: {
                message: '填写失败',
                validators: {
                    notEmpty: {
                        message: '该项信息不能为空'
                    }
                }
            }

        }

    });
});

// Validate the form manually
$('#validateBtn').click(function() {
    $('form').bootstrapValidator('validate');
});

$('#resetBtn').click(function() {
    $('form').data('bootstrapValidator').resetForm(true);
});


// 文件上传组件
$("#form_file").fileinput({
    uploadUrl:baseURL + "sys/file/upload", //接受请求地址
    uploadAsync : true, //默认异步上传
    showUpload : true, //是否显示上传按钮,跟随文本框的那个
    showRemove : true, //显示移除按钮,跟随文本框的那个
    showCaption : true,//是否显示标题,就是那个文本框
    showPreview : true, //是否显示预览,不写默认为true
    dropZoneEnabled : false,//是否显示拖拽区域，默认不写为true，但是会占用很大区域
    //minImageWidth: 50, //图片的最小宽度
    //minImageHeight: 50,//图片的最小高度
    //maxImageWidth: 1000,//图片的最大宽度
    //maxImageHeight: 1000,//图片的最大高度
    //maxFileSize: 0,//单位为kb，如果为0表示不限制文件大小
    //minFileCount: 0,
    maxFileCount : 1, //表示允许同时上传的最大文件个数
    enctype : 'multipart/form-data',
    validateInitialCount : true,
    previewFileIcon : "<i class='glyphicon glyphicon-king'></i>",
    msgFilesTooMany : "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
    allowedFileExtensions : [ 'zip','xlsx','xls','pdf','docx','doc' ],//配置允许文件上传的类型
    // allowedPreviewTypes : [ 'image' ],//配置所有的被预览文件类型
    // allowedPreviewMimeTypes : [ 'jpg', 'png', 'gif' ],//控制被预览的所有mime类型
    language : 'zh'
})
//异步上传返回结果处理
$('#form_file').on('fileerror', function(event, data, msg) {
    console.log("fileerror");
    console.log(data);
});
//异步上传返回结果处理
$("#form_file").on("fileuploaded", function(event, data, previewId, index) {
    console.log("fileuploaded");
    var response = data.response;
    console.log(data.files[0].name);
    alert("已上传文件:"+response.filename);
    vm.b108BasicLivingAllowancesRate.filepath=response.filename;
    $("#uploadfilename").val(response.filename);
    //$("#uploadfilename").trigger('change');




    // $("#fileMd5").val(response.fileMd5);
    // $("#version").val(response.newVersionName);
    // $("#url").val(response.filePath);

});

//上传前
$('#form_file').on('filepreupload', function(event, data, previewId, index) {
    console.log("filepreupload");
    console.log(data.files[0].name);
    //vm.b63AverageSpeedPeak.filePath=data.files[0].name;

});